
package com.eyedog.video.maincategory;

import com.eyedog.video.constant.Constants;
import com.eyedog.video.entity.CategoryEntity;
import com.eyedog.video.http.ICallback;

import java.util.List;

public class CategoryInstance implements constract.ICategoryModel {

    private CategoryInstance() {
    }

    enum Instance {
        INSTANCE;

        CategoryInstance instance;

        Instance() {
            instance = new CategoryInstance();
        }
    }

    public static CategoryInstance getInstance() {
        return Instance.INSTANCE.instance;
    }

    List<CategoryEntity> categoryEntities;

    @Override
    public void loadCategories(final ICallback<List<CategoryEntity>> callback) {
        if (categoryEntities == null) {
            CategroyModel model = new CategroyModel();
            model.loadCategories(new ICallback<List<CategoryEntity>>() {
                @Override
                public void onLoadSuccess(List<CategoryEntity> categoryEntities) {
                    getInstance().categoryEntities = categoryEntities;
                    getInstance().categoryEntities.add(0,
                            new CategoryEntity(Constants.Category_NewId, "最新"));
                    getInstance().categoryEntities.add(0,
                            new CategoryEntity(Constants.Category_RecommendId, "推荐"));
                    callback.onLoadSuccess(getInstance().categoryEntities);
                }

                @Override
                public void onLoadFailed(String err) {
                    callback.onLoadFailed(err);
                }
            });
        } else {
            callback.onLoadSuccess(categoryEntities);
        }
    }
}
